package org.apache.derby.impl.drda;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Hashtable;

/**
 * @author ex_chenzy59
 * @since 2025/3/6
 *
 */
public class Session {
    protected InputStream sessionInput;
    protected OutputStream sessionOutput;
    protected Socket clientSocket;
    protected int connNum;
    private Hashtable<String, Database> dbtable;
    protected int getConnNum()
    {
        return connNum;
    }
    protected void close() throws SQLException
    {

        try {
            sessionInput.close();
            sessionOutput.close();
            clientSocket.close();
            setTraceOff();
            if (dbtable != null)
                for (Enumeration e = dbtable.elements(); e.hasMoreElements() ;)
                {
                    ((Database) e.nextElement()).close();
                }

        }catch (IOException e) {} // ignore IOException when we are shutting down
        finally {
            state = CLOSED;
            dbtable = null;
            database = null;
        }
    }
    protected void setTraceOff()
    {
        if (! traceOn)
            return;
        traceOn = false;
        if (traceFileName != null)
            dssTrace.stopComBufferTrace();
    }
}
